//
//  ZH_HomeVedioTableViewCell.m
//  WisdomStar
//
//  Created by zhangliwen on 2018/10/25.
//  Copyright © 2018年 zhangliwen. All rights reserved.
//

#import "ZH_HomeVedioTableViewCell.h"
@interface ZH_HomeVedioTableViewCell()
@property (nonatomic,weak)UIView *bgView;
@property (nonatomic,weak)UIImageView *bgImage;
@property (nonatomic,weak)UILabel *titleLabel;
@property (nonatomic,weak)UILabel *numLabel;
@property (nonatomic,weak)UIImageView *lookImage;
@property (nonatomic,weak)UILabel *contentLabel;
@property (nonatomic,weak)UIButton *lookButton;
@property (nonatomic,weak)UIButton *vedioButton;
@end
@implementation ZH_HomeVedioTableViewCell

///创建
+(instancetype)cellWithTableView:(UITableView*)tableView
{
    static NSString *ID = @"ZH_HomeVedioTableViewCell";
    ZH_HomeVedioTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if(cell == nil){
        cell = [[ZH_HomeVedioTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}
///初始化
-(void)initDefault
{
    [self unShowClickEffect];
    //    self.bottomShortLineImage.hidden = NO;
}
- (void)loadSubviewConstraints{
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(FITSCALE(9));
        make.left.equalTo(self.contentView).offset(FITSCALE(11));
        make.right.equalTo(self.contentView).offset(FITSCALE(-11));
        make.height.mas_equalTo(FITSCALE(227));
        make.bottom.equalTo(self.contentView);
    }];
    [self.bgImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(FITSCALE(9));
        make.left.equalTo(self.bgView).offset(FITSCALE(0));
        make.right.equalTo(self.bgView).offset(FITSCALE(0));
        make.height.mas_equalTo(FITSCALE(141));
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bgImage.mas_bottom).offset(FITSCALE(21));
        make.left.equalTo(self.bgImage).offset(FITSCALE(11));
    }];
    [self.numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.titleLabel);
        make.right.equalTo(self.bgImage).offset(FITSCALE(-11));
    }];
    [self.lookImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.numLabel);
        make.right.equalTo(self.numLabel.mas_left).offset(FITSCALE(-4));
    }];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(FITSCALE(18));
        make.left.equalTo(self.titleLabel);
    }];
    [self.lookButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentLabel);
        make.right.equalTo(self.bgView).offset(FITSCALE(-11));
        make.height.mas_equalTo(FITSCALE(22));
        make.width.mas_equalTo(FITSCALE(44));
    }];
    [self.vedioButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.bgImage);
    }];
}
- (void)updataUI:(NSMutableDictionary *)data{
    if (data) {
        [self.bgImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",SERVER_TEST,data[@"image"]]] placeholderImage:nil];
        self.titleLabel.text = data[@"cate_name"];
        if (![data[@"introduction"] isKindOfClass:[NSNull class]]) {
             self.contentLabel.text = data[@"introduction"];
        }
        self.numLabel.text = [NSString stringWithFormat:@"(%@)",data[@"scan"]];
    }
}
#pragma mark - getter,setter
- (UIView *)bgView{
    if (!_bgView) {
        UIView *view = [UIView createViewWithBackgroundColor:kFontColorWhite];
        view.layer.cornerRadius = FITSCALE(3);
        view.layer.masksToBounds = YES;
        view.clipsToBounds = YES;
        [self.contentView addSubview:_bgView = view];
    }
    return _bgView;
}
- (UIImageView *)bgImage{
    if (!_bgImage) {
        UIImageView *image = [UIImageView createImageViewWithName:@"img_banner"];
        image.layer.masksToBounds = YES;
        image.clipsToBounds = YES;
        [self.contentView addSubview:_bgImage = image];
    }
    return _bgImage;
}
- (UILabel *)titleLabel{
    if (!_titleLabel) {
        UILabel *label = [UILabel createLabelWithText:@"标题信息..." font:kFontSize_28];
        [self.contentView addSubview:_titleLabel = label];
    }
    return _titleLabel;
}
- (UILabel *)numLabel{
    if (!_numLabel) {
        UILabel *label = [UILabel createLabelWithText:@"(12)" font:kFontSize_26];
        label.textColor = [UIColor colorWithHexString:@"#999999"];
        label.textAlignment = NSTextAlignmentRight;
        [self.contentView addSubview:_numLabel = label];
    }
    return _numLabel;
}
- (UIImageView *)lookImage{
    if (!_lookImage) {
        UIImageView *image = [UIImageView createImageViewWithName:@"icon_eyes"];
        [self.contentView addSubview:_lookImage = image];
    }
    return _lookImage;
}
- (UILabel *)contentLabel{
    if (!_contentLabel) {
        UILabel *label = [UILabel createLabelWithText:@"视频简介..." font:kFontSize_24];
        label.textColor = [UIColor colorWithHexString:@"#999999"];
        [self.contentView addSubview:_contentLabel = label];
    }
    return _contentLabel;
}
- (UIButton *)lookButton{
    if (!_lookButton) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"查看" target:self action:nil];
        [button setTitleColor:kFontColorWhite forState:UIControlStateNormal];
        button.backgroundColor = [UIColor colorWithHexString:@"#00C9AE"];
        button.layer.cornerRadius = FITSCALE(10);
        button.layer.masksToBounds = YES;
        button.clipsToBounds = YES;
        [self.contentView addSubview:_lookButton = button];
    }
    return _lookButton;
}
- (UIButton *)vedioButton{
    if (!_vedioButton) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"" target:self action:nil];
        [button setImage:[UIImage imageNamed:@"icon_spplay"] forState:UIControlStateNormal];
        [self.contentView addSubview:_vedioButton = button];
    }
    return _vedioButton;
}
@end
